<html>
<head>
	<meta charset='utf-8' />
	<title>便民信息</title>
	<meta http-equiv="keywords" content="求职,招聘,房屋,出租,出售,求租,求购,宠物,二手,二手车,二手物品,旧货,寻物,寻人,出兑,外兑"> 
	<meta http-equiv="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息">  
	<meta name="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息"/>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#nav_bottom{width:98%;margin:0 auto}
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#nav_bottom{width:450px;margin:0 auto}
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body style='padding:0;margin:0;background:#eee'>
<!-- 1 Content容器 -->
<div id='Content'>


	<!-- 2 顶部广容器-->
	<div style='height:70px;border:1px solid #369;display:flex;text-align:center' id='Advert_Top'>

	</div><!-- 2 顶部广容器结束-->





	<!-- 3 内容区-->
	<div style='margin:10px 0;word-break:break-all;padding:10px;border:1px solid #ccc'>
		<h2 style='text-align:center'>信息管理</h2>

		<!--信息列表-->
		<div id='info_list' style='color:#888'></div>

		
		<!--分页-->
		<div style='text-align:center' id='fpage'></div>

	</div>	<!-- 3 内容区结束-->	






	<!--底部广告-->
	<div style='height:80px;border:0px solid red;margin-bottom:45px' id='Advert_Bottom'>

	</div><!--底部广告结束-->

</div><!-- 1 Content容器结束 -->





<!--底部导航容器-->
<div id='Nav_Bottom' style='position:fixed;bottom:0;width:100%;height:45px'>

</div><!--底部导航容器结束-->


</body>
</html>
<script src='./Public/jquery.js'></script>
<script src='./Public/fun.js'></script>
<script>
	$(function(){

		Set_Title();	//设置页面title
		
		Set_Advert_Top();	//临时设置顶部广告

		if(sessionStorage.me_res && sessionStorage.tmp_time){
		//	console.log(unescape(sessionStorage.me_res));
			if(parseInt(sessionStorage.tmp_time) + 10000 > new Date().getTime()){
				console.log('sess_get')
				Res_Con(unescape(sessionStorage.me_res));
			}else{
				Get_Me_Info();	//获取我发布的信息
			}
		}else{
			Get_Me_Info();	//获取我发布的信息
		}

	});

	//检测用户登陆状态，是否跳到login页面
	Check_Login();

	//加载底部导航栏
	Load_NavBottom('before');



	//遍历数据并填充数据到元素
    function Insert_Item(info) {
        if (!info || info.length < 1) {
            return;
        }
		//获取服务列表数据
		GetServiceList();

		var service_type = JSON.parse(sessionStorage.service_type);

		var server_date = new Date(parseInt(sessionStorage.me_server_stamp));
		var pcount = parseInt(sessionStorage.me_pcount);
		var psize = parseInt(sessionStorage.me_psize);
		var pstart = (parseInt(sessionStorage.me_pnow)-1)*psize;
		var pend = pstart + psize;
		if(pend > pcount){
			pend = pcount;
		}
		var c_str = '';
        //info_id,info_service,info_title,info_issue_time,info_auto_issue,info_stat
      //  alert(info[1][4]);
		for(var i=pstart;i<pend;i++){
			var service_name = Get_ServiceType_Name(service_type,info[i][1]);


            var date = new Date(parseInt(info[i][3])*1000);	//是否自动重发显示当天时间

			switch(info[i][5]){
				case '0':
				case 0:var issue_str = '<span style="color:green">审核中</span>';break;
				case '1':
				case 1:
					if(info[i][4] == 1){
						var issue_str = '<span style="color:blue">自动发布</span>';
					}else{
						var issue_str = '<span style="color:blue">正常</span>';
					}
				break;
				case '2':
				case 2:var issue_str = '<span style="color:#aaa">已删除</span>';break;
				case '3':
				case 3:var issue_str = '<span style="color:red">已封禁</span>';break;
				case '4':
				case 4:var issue_str = '<span style="color:green">审核中</span>';break;
			}
			var date2 = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
			c_str += "<div class='Info_Item' style='border-bottom:1px solid #ddd;padding-bottom:5px;margin-bottom:10px'>";

			//正常和待审的不加删除 
            if (info[i][5] == 2){
                c_str += "<div class='item_title' style='color:#aaa;text-decoration:line-through' onclick=Info_Cat(" + info[i][0]+",'me')>"+info[i][2]+"</div>";
			}else{
				//封禁和审核中的信息不能查看详情
                if (info[i][5] == '0' || info[i][5] == '3' || info[i][5] == '4'){
                    c_str += "<div class='item_title' style='color:#66f' >" + info[i][2]+"</div>";
				}else{
                    c_str += "<div class='item_title' style='color:#66f' onclick=Info_Cat(" + info[i][0] + ",'me')>" + info[i][2]+"</div>";
				}
			}
			c_str += "<div style='display:flex'>";
			c_str += "<div style='flex:1;font-size:12px'>";
			c_str += "<span class='item_service'>"+service_name+"</span>　";
			c_str += "<span class='item_time'>"+date2+"</span>";
			c_str += "<span class='item_time'>　"+issue_str+"</span>";
			c_str += "</div>";
			c_str += "<div style='flex:1;text-align:right'>";
            if (info[i][5] != 2 && info[i][5] != 3){
				c_str += "<button class='item_edit' onclick='Info_Edit("+info[i][0]+")' >编辑</button>　";

               	c_str += "<button class='item_del' onclick='Info_Del(" + info[i][0]+","+info[i][4]+")' >删除</button>";
			
			}
			c_str += "</div></div></div>";
		}
		$('#info_list').html(c_str);

		//分页实现
		if(parseInt(sessionStorage.me_pnum) > 1){
			Fpage(sessionStorage.me_pnum, sessionStorage.me_pnow,function(pnow){
				sessionStorage.me_pnow = pnow;
				Insert_Item(info);
			});
		}else{
			$('#fpage').html('');
		}

	}


	//res数据处理
    function Res_Con(res) {
        if (!/^\[.*\]$/.test(res)) {
        	console.log('null');
            return;
        }

		var info = JSON.parse(res);
		var item = $('.Info_Item').clone();
		//总条数
		sessionStorage.me_pcount = info.length;
		//每页条数
		sessionStorage.me_psize = 5;
		//总页数
		sessionStorage.me_pnum = Math.ceil(parseInt(sessionStorage.me_pcount)/parseInt(sessionStorage.me_psize));
		//当前页
		if(!sessionStorage.me_pnow || sessionStorage.me_pnum < 2){
			sessionStorage.me_pnow = 1;
		}
		//遍历数据并添加到元素中
		Insert_Item(info);
	}





	//修改信息
    function Info_Edit(iid) {
		location.href='me_edit.html?iid='+iid+'&r='+Math.random();
	}


	//删除信息
    function Info_Del(iid, issue) {
		if(!confirm('确认删除该信息?')){
			return;
		}
        var type = 'Del_Me_Info';
		Token(type,function(token){
			$.ajax({
				url:url,
				type:'post',
				data:{
					type:type,
					iid:iid,
					issue:issue,
					uid:GetUid('uid'),
					token:token
				},
				success(res){
					//alert(res);return;
					//document.write(res);return;
					switch(res){
						case 'err':alert('删除失败！');break;
						case 'err2':alert('删除失败！');break;
						case 'ok':
							alert('删除成功！');
							Get_Me_Info();
						break;
					}
				}
			});
		})
	}


	//获取我发布的信息列表 
	function Get_Me_Info(){
		sessionStorage.tmp_time = new Date().getTime();
		var type = 'Get_Me_Info';
		$.ajax({
			url:'Cache/User/'+GetUid('uid')+'?r='+Math.random(),
			async:false,
			type:'post',
           success: function (res, a, b) {
           		console.log('cache_get');
		        //保存服务器时间戳
		        sessionStorage.me_server_stamp = new Date(b.getResponseHeader('Date')).getTime();
		        sessionStorage.me_res = escape(res);
				Res_Con(res);
			},
           error: function () {
				Token(type,function(token){
					$.ajax({
						url:url,
						type:'post',
						data:{
							type:type,
							token:token,
							uid:GetUid('uid')
						},
                        success(res, a, b) {
           					console.log('after_get');
                            if (!res) {
								$("#info_list").html('');
							}else{
						        //保存服务器时间戳
						        sessionStorage.me_server_stamp = new Date(b.getResponseHeader('Date')).getTime();
		        				sessionStorage.me_res = escape(res);
								Res_Con(res);
							}
						}
					});
				})
			}
		});
	}

		
</script>












